package teamgodeater.hicarnet.Fragment;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.rey.material.widget.Switch;
import com.sample.andremion.musicplayer.music.MusicControl;

import java.util.List;

import teamgodeater.hicarnet.Adapter.BaseItem2LineAdapter;
import teamgodeater.hicarnet.Data.BaseItem2LineData;
import teamgodeater.hicarnet.R;

/**
 * Created by G on 2016/7/24 0024.
 */

public class DrwaerRvAdapter extends BaseItem2LineAdapter {
    private static final int NOMAL_ITEM = 1, SLIDE_ITEM = 2;

    public DrwaerRvAdapter(List<? extends BaseItem2LineData> l) {
        super(l);
    }


    @Override
    public int getItemViewType(int position) {
        return position == list.size() - 1 ? SLIDE_ITEM : NOMAL_ITEM;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == SLIDE_ITEM) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_ico_2line_slide, parent, false);
            return new SlideHolder(v);
        }
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder vvholder, final int position) {
        super.onBindViewHolder(vvholder, position);
        if (vvholder instanceof  SlideHolder) {
            final SlideHolder slideHolder = (SlideHolder) vvholder;
            slideHolder.switchButton.setChecked(MusicControl.isAutoPlay());
            slideHolder.switchButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MusicControl.setAutoPlay(slideHolder.switchButton.isChecked());
                }
            });
        }
    }

    public class SlideHolder extends BaseItem2LineHolder {
        public Switch switchButton;
        public SlideHolder(View itemView) {
            super(itemView);
            switchButton = (Switch) itemView.findViewById(R.id.switchButton);

        }
    }

}
